package com.hitplane.manager 
{
	import com.hitplane.core.ObjectPool;
	import com.hitplane.interfaces.IRecyclable;
	
	import flash.utils.getQualifiedClassName;

	/**
	 * 对象池管理
	 * 单例模式类
	 * @author 郑子华
	 */
	public class ObjectPoolManager
	{
		private static var _instance:ObjectPoolManager = null;
		public function ObjectPoolManager(single:Single) 
		{
			
			if(single == null)
			{
				throw new Error("Can't create instance , Single is Null!");
			}
		}
		/**
		 * 单例引用
		 */
		public static function get instance():ObjectPoolManager
		{
			if(_instance == null)
			{
				_instance = new ObjectPoolManager(new Single());
			}
			return _instance;
		}
		/**
		 * objectPool对象集合
		 * 以实例类名为键，实例为值存储
		 */ 
		private var objectPoolArr:Array = [];
		/**
		 * 获取对象
		 * @param type
		 * 
		 */
		public function getObjByClass(type:Class):IRecyclable {
			var typeName:String=getQualifiedClassName(type);
			if(objectPoolArr[typeName]==null){
				objectPoolArr[typeName]=new ObjectPool(type);
			}
			var objectPool:ObjectPool=objectPoolArr[typeName] as ObjectPool;
			return objectPool.getObject();
		}
		/**
		 * 回收对象
		 * @param	o
		 */
		public function recoveObj(o:IRecyclable):void {
			var typeName:String=getQualifiedClassName(o);
			var objectPool:ObjectPool=objectPoolArr[typeName] as ObjectPool;
			objectPool.recoverObj(o);
		}
	}
}
class Single{}